using GameFramework;
using Unity.VisualScripting;
using UnityEngine;
using UnityGameFramework.Runtime;

namespace LS.UGFUnits
{
    [UnitShortTitle("Data Node")]
    [UnitSurtitle("Delete")]
    public sealed class DeleteDataNode : DataNodeUnit
    {
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueInput Path { get; private set; }
        

        protected override void Definition()
        {
            base.Definition();
            Path = ValueInput<string>(nameof(Path), string.Empty);
            Requirement(Path, Input);
            Succession(Input, Output);
        }

        private ControlOutput In(Flow flow)
        {
            if (Target == null)
            {
                Debug.LogError("GameFramework is not initialized.");
                return Output;
            }

            string path = flow.GetValue<string>(Path);
            Target?.RemoveNode(path);
            return Output;
        }
    }
}